using System.Collections;
using System.Collections.Generic;
using System.Data;
using UnityEngine;

public class NumRoll : MonoBehaviour
{
    public bool open = false;
    public int row = 10;
    [Range(0,10)]public float speed = 1;
    public Material mat;
    private float _curVal;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        StartRoll();
    }

	void StartRoll()
	{
	    if (mat != null && open)
	    {
	        _curVal += 1.0f / row * speed * Time.deltaTime; 
	        _curVal = _curVal % 10;
            mat.SetFloat("_CurVal", _curVal);
        }

	    if (mat != null)
	    {
	        if (open == false || speed <= 0)
	        {
	            _curVal = Mathf.Round(_curVal * 10)/10 ;
                mat.SetFloat("_CurVal", _curVal);
            }
	    }
	}
}
